<template>
  <div class="dashboard-container">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="单张价格">
        <el-input v-model="form.price"></el-input>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button>清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveSetting, getSetting }  from '@/api/setting'
import { mapGetters }               from 'vuex'
import { Message }                  from 'element-ui'

export default {
  name: 'Dashboard',
  components: {  },
  data() {
    return {
      currentRole: 'adminDashboard',
      id: null,
      form: {
        price: 0
      }
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    this.Config()
  },
  methods: {
    // 获取基本配置
    Config() {
      getSetting({name: 'pic'}).then(response => {
        this.form.price       = response.data.unitPrice
        this.id               = response.data.id
      })
    },
    // 提交表单
    onSubmit() {
      saveSetting({id: this.id, unitPrice: this.form.price}).then(response => {
        if (response.state == 200) {
          Message({
            message: response.message || 'success',
            type: 'success',
            duration: 2 * 1000
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .dashboard-container {
    padding: 20px 10px
  }
  .btn-wrap{
    padding: 0 10px
  }
</style>